<?php use_stylesheets_for_form($form) ?>
<?php use_javascripts_for_form($form) ?>
<?php use_javascript('jquery.ui.core.js')?>
<?php use_javascript('jquery.ui.datepicker.js')?>
<?php use_javascript('date.js')?>
<?php use_stylesheet('jquery-ui-1.8.1.custom.css')?>
<?php use_javascript('jquery.calculation.js')?>

<form action="<?php echo url_for('comprasespeciales/'.($form->getObject()->isNew() ? 'create' : 'update').(!$form->getObject()->isNew() ? '?id='.$form->getObject()->getId() : '')) ?>" method="post" <?php $form->isMultipart() and print 'enctype="multipart/form-data" ' ?>>
<?php if (!$form->getObject()->isNew()): ?>
<input type="hidden" name="sf_method" value="put" />
<?php endif; ?>
  <table>
    <tfoot>
      <tr>
        <td colspan="2">
          <?php echo $form->renderHiddenFields(false) ?>
          <?php echo button_to('Volver a Compras','comprasespeciales/index') ?>
          <?php if (!$form->getObject()->isNew()): ?>
            &nbsp;<?php echo link_to('<button>Delete</button>', 'comprasespeciales/delete?id='.$form->getObject()->getId(), array('method' => 'delete', 'confirm' => 'Are you sure?')) ?>
          <?php endif; ?>
          <input type="submit" value="Guardar" />
        </td>
      </tr>
    </tfoot>
    <tbody>
      <?php echo $form->renderGlobalErrors() ?>
      <tr>
        <th><?php echo $form['cuenta_id']->renderLabel() ?></th>
        <td>
          <?php echo $form['cuenta_id']->renderError() ?>
          <?php echo $form['cuenta_id']; echo $form['estado'] ?>
        </td>
      </tr>
      <tr>
        <th><?php echo $form['nombre_encargado']->renderLabel() ?></th>
        <td>
          <?php echo $form['nombre_encargado']->renderError() ?>
          <?php echo $form['nombre_encargado'] ?>
        </td>
      </tr>
      <tr>
        <th><?php echo $form['correo_encargado']->renderLabel() ?></th>
        <td>
          <?php echo $form['correo_encargado']->renderError() ?>
          <?php echo $form['correo_encargado'] ?>
        </td>
      </tr>
      <tr>
        <th><?php echo $form['anexo_encargado']->renderLabel() ?></th>
        <td>
          <?php echo $form['anexo_encargado']->renderError() ?>
          <?php echo $form['anexo_encargado'] ?>
        </td>
      </tr>
      <tr>
        <th><?php echo $form['cotizacion']->renderLabel() ?></th>
        <td>
          <?php echo $form['cotizacion']->renderError() ?>
          <?php echo $form['cotizacion'] ?>
        </td>
      </tr>
      <?php if($sf_user->hasCredential('Abastecimiento')):?>
      
      <tr>
        <th><?php echo $form['plazo_entrega']->renderLabel() ?></th>
        <td>
          <?php echo $form['plazo_entrega']->renderError() ?>
          <?php echo $form['plazo_entrega'] ?>
        </td>
      </tr>
      
      <?php endif ?>
      <tr>
        <th>Valor Neto</th>
        <td>
          <?php echo $form['neto']->renderError() ?>
          <?php echo $form['neto'] ?>
        </td>
      </tr>
      <tr>
        <th>Iva (19%)</th>
        <td>
          <?php echo $form['iva']->renderError() ?>
          <?php echo $form['iva'] ?>
        </td>
      </tr>
      <tr>
        <th>Valor Total</th>
        <td>
          <?php echo $form['total']->renderError() ?>
          <?php echo $form['total'] ?>
        </td>
      </tr>
    </tbody>
  </table>
</form>

<script type="text/javascript">
	function actualiza(){
		var neto_txt = document.getElementById('neto_txt');
		var iva_txt = document.getElementById('iva_txt');
		var total_txt = document.getElementById('total_txt');
		if(neto_txt.value != "" && /^[0-9]+$/.test(neto_txt.value))
		{
				var neto = parseInt(neto_txt.value);
				var iva = parseInt(neto * 0.19);
				var total = neto + iva;
				iva_txt.value = iva.toString();
				total_txt.value = total.toString();
		}	
		else
		{
				iva_txt.value = 'Error';
				total_txt.value = 'Error';
		}	
	}
</script>
